
/*
 * This is the extension predicate for an activity associated
 * with service '{http://www.pi4soa.org/AuctionHouseBuyer}Broker'
 * and behavior 'main_Broker'. The name of the
 * activity is 'TransactionNotValid'.
 */
package org.pi4soa.auctionhousebuyer.broker.main_broker;

import org.pi4soa.service.extensions.DefaultActivityExtension;
import org.pi4soa.service.extensions.PredicateExtension;
import org.pi4soa.service.extensions.ExtensionContext;
import org.pi4soa.service.ServiceEvent;
import org.pi4soa.service.UnresolvedConstraintException;
import org.pi4soa.service.ServiceException;
import org.pi4soa.service.DeferProcessingException;

import dk.itu.amds.broker.data.BrokerDB;

/**
 * This class has been autogenerated to implement the custom
 * predicate within a service endpoint description.
 */
public class TransactionNotValidPredicate extends DefaultActivityExtension
					implements PredicateExtension {

	/**
	 * The constructor for the predicate extension.
	 */
	public TransactionNotValidPredicate() {
	}
	
	/**
	 * This method determines whether the predicate extension
	 * is satisfied.
	 * 
	 * @param context The context
	 * @param event The current event being processed
	 * @return Whether the extension predicate is satisfied
	 * @exception UnresolvedConstraintException The predicate cannot
	 * 				be resolved due to lack of information
	 * @exception DeferProcessingException Suspend processing
	 * @exception ServiceException Failed to evaluate predicate
	 */
	public boolean isSatisfied(ExtensionContext context,
					ServiceEvent event)
			throws UnresolvedConstraintException,
					DeferProcessingException, ServiceException {
		boolean ret=false;

		int buyerBrokerAccountId  = Integer.parseInt(context.getVariable("buyerBrokerAccountId").toString());
		int sellerBrokerAccountId = Integer.parseInt(context.getVariable("sellerBrokerAccountId").toString());
		float transferAmount = Float.parseFloat(context.getVariable("transferAmount").toString());
		/*
		if(BrokerDB.validate(buyerBrokerAccountId, sellerBrokerAccountId, transferAmount)){
			ret = false;
		} else {
			ret = true;
		}
		*/
		ret = !BrokerDB.validate(buyerBrokerAccountId, sellerBrokerAccountId, transferAmount);
		System.err.println("Not valid is: " + ret);
		// TODO: Add code to determine if the predicate
		// is satisfied.
		
		return(ret);
	}
}	